package com.example.goods_admin.controller;


import com.example.goods_admin.common.Result;
import com.example.goods_admin.entity.Goods;
import com.example.goods_admin.service.UploadFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/upload")
public class UploadFileController {

    @Autowired
    UploadFileService uploadFileService;

    @PostMapping("/uploadImage")
    public Result uploadImage(@RequestPart MultipartFile[] file,@RequestParam("id") String id) {
        return uploadFileService.uploadImage(file,id);
    }
    @PostMapping("/saveGoods")
    public Result saveGoods(@RequestBody Goods goods) {
        return uploadFileService.saveGoods(goods);
    }

    @PostMapping("/deleteGoodsImage")
    public Result deleteGoodsImage(@RequestBody Goods goods,@RequestParam("imgId") String imgId) {
        return uploadFileService.deleteGoodsImage(goods,imgId);
    }

    @PostMapping("/selectGoods")
    public Result selectGoods(@RequestBody Goods goods) {
        return uploadFileService.selectGoods(goods);
    }
    @PostMapping("/selectGoodsList")
    public Result selectGoodsList(@RequestBody Goods goods) {
        return uploadFileService.selectGoodsList(goods);
    }

    @PostMapping("/deleteGoods")
    public Result deleteGoods(@RequestBody Goods goods) {
        return uploadFileService.deletegoods(goods);
    }

    //json传参
    @PostMapping("/editGoods")
    public Result editGoods(@RequestBody Goods goods) {
        return uploadFileService.editGoods(goods);
    }


    //params传参
    @RequestMapping(value = "/test" ,method = {RequestMethod.GET,RequestMethod.POST})
    public String editGoods1(@RequestParam String id, String name) {
        System.out.println(id);
        System.out.println(name);

        return id;
    }

    //路径传参
    @RequestMapping(value = "/test2/{id}/{name}" ,method = {RequestMethod.GET,RequestMethod.POST})
    public String editGoods12(@PathVariable String id, @PathVariable String name) {
        System.out.println(id);
        System.out.println(name);
        System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        System.out.println("####");

        return id;
    }


    //query传参
    @RequestMapping(value = "/test3" ,method = {RequestMethod.GET,RequestMethod.POST})
    public String editGoods123(@RequestParam String id, @RequestParam String name) {
        System.out.println(id);
        System.out.println(name);

        return id;
    }
}
